package com.sevattal.service.leaves.controller;


import com.sevattal.common.base.result.R;
import com.sevattal.service.leaves.entity.vo.ApplyForOrderVo;
import com.sevattal.service.leaves.entity.vo.AuditOrderVo;
import com.sevattal.service.leaves.service.ApplyForOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 申领主表 前端控制器
 * </p>
 *
 * @author Sevattal
 * @since 2021-08-28
 */
@Api(tags = "申领单管理")
@RestController
@RequestMapping("/admin/leaves/apply-for-order")
public class ApplyForOrderController {

    @Autowired
    private ApplyForOrderService applyForOrderService;


    @ApiOperation("新建申领单")
    @PostMapping("createApplyOrder")
    public R createApplyOrder(@ApiParam(value = "申领单对象",required = true) @RequestBody ApplyForOrderVo applyForOrderVo){
        boolean result = applyForOrderService.createApplyOrder(applyForOrderVo);
        if (result) {
            return R.ok().message("创建成功");
        }else{
            return R.error().message("创建失败");
        }
    }

    @ApiOperation("修改申领单")
    @PutMapping("updateApplyOrder")
    public R updateApplyOrder(@ApiParam(value = "申领单主表对象",required = true) @RequestBody ApplyForOrderVo applyForOrderVo) {
        boolean result = applyForOrderService.updateApplyOrder(applyForOrderVo);
        if (result) {
            return R.ok().message("修改成功");
        }else{
            return R.error().message("修改失败");
        }
    }

    @ApiOperation("删除申领单")
    @DeleteMapping("deleteApplyOrder/{id}")
    public R deleteApplyOrder(@ApiParam(value = "供应商id",required = true) @PathVariable String id) {
        boolean result = applyForOrderService.deleteApplyOrder(id);
        if (result) {
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }


    @ApiOperation("获取申领单信息")
    @PostMapping("getApplyOrderList")
    public R getApplyOrderList(@ApiParam(value = "供应商对象",required =  true)  @RequestBody ApplyForOrderVo applyForOrderVo){
        List<ApplyForOrderVo> applyForOrderList = applyForOrderService.getApplyOrderList(applyForOrderVo);
        return R.ok().data("applyForOrderList",applyForOrderList);
    }

    @ApiOperation("审批申领单")
    @PostMapping("auditApplyOrder")
    public R auditApplyOrder(@ApiParam(value = "审批对象",required = true) @RequestBody AuditOrderVo auditOrderVo){
        boolean result = applyForOrderService.auditOrder(auditOrderVo);
        if (result) {
            return R.ok().message("操作成功");
        }else {
            return R.error().message("操作失败");
        }
    }


}

